package cn.lfy.studentmanager.dao;

import java.util.List;
import java.util.Map;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import cn.lfy.studentmanager.domain.Academy;
import cn.lfy.studentmanager.domain.Department;

public interface DepartmentDao {
	//实现新增
	@Insert("INSERT INTO department(name,aid) VALUES(#{name},#{aid})")
	@Options(useGeneratedKeys=true, keyProperty="id", keyColumn="id")
	boolean add(Department department);
	
	//实现查询
	@Select("SELECT d.id, d.name, d.aid, a.name as aname FROM department d "
			+ "INNER JOIN academy a ON d.aid = a.id limit #{start},#{limit}")
	List<Map<String, Object>> select(int start, int limit);
	
	//进行删除操作
	@Delete("DELETE FROM department WHERE id =#{id}")
	boolean delete(int id);
	
	//完成修改数据
	@Update("UPDATE department SET name=#{name}, aid=#{aid} WHERE id=#{id}")
	boolean update(int id,String name,int aid);
	
	//完成分页，本质还是查询
	@Select("SELECT COUNT(*) FROM department")
	int getCount();
	
	//查询系表中所有name
	@Select("SELECT * FROM department")
	List<Department> selectAll();


}
